<%--
  Created by IntelliJ IDEA.
  log: Administrator
  Date: 2020/9/11
  Time: 15:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>首页--汽车租赁系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/public.css" media="all" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui_ext/dtree/dtree.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui_ext/dtree/font/dtreefont.css">
</head>
<body class="childrenBody">
<!-- 搜索条件开始 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>查询条件</legend>
</fieldset>
<form class="layui-form" method="post" id="searchFrm">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">登录名称:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="loginname" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入登录名称" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">登录IP:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="loginip" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入登录IP" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">开始时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="starttime" id="starttime" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入开始时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">结束时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="endtime" id="endtime" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入结束时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
            </div>
    <div class="layui-form-item">
        <div class="layui-input-black" style="text-align: center">
            <button   class="layui-btn layui-btn-normal layui-icon layui-icon-search layui-btn-radius layui-btn-sm" lay-submit  lay-filter="doSearch">查询
            </button>
            <button type="reset" class="layui-btn layui-btn-warm layui-icon layui-icon-refresh layui-btn-radius layui-btn-sm">重置
            </button>
        </div>
    </div>
</form>


<!-- 搜索条件结束 -->
<table id="logTable" lay-filter="logTable"></table>

<script id="toolbarlog" type="text/html">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="delBatch">批量删除</button>
    </div>
</script>

<script id="barlog" type="text/html">
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-radius" lay-event="del">删除</a>
</script>
<%-- 分配角色开始 --%>
<div style="display: none" id="sellogRoleDiv">
    <table id="roleTable" lay-filter="roleTable"></table>
</div>



<%-- 添加或者修改弹出框开始 --%>
<div style="display: none" id="saveOrUpdateDiv">
    <form class="layui-form" lay-filter="dataFrm" id="dataFrm">
        <div class="layui-form-item">
            <label class="layui-form-label">身份证ID:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="hidden" name="logid" id="logid">
                <input type="text" name="identity" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入身份证号码" style="height: 30px;border-radius: 10px">
            </div>
            <label class="layui-form-label">登录名称:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="loginname" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入登录名称" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">登录密码:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="password" name="pwd" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入登录密码" style="height: 30px;border-radius: 10px">
            </div>
            <label class="layui-form-label">真实姓名:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="realname" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入真实姓名" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">性别:</label>
                <div class="layui-input-inline">
                    <input type="radio" name="sex" value="1" checked title="男">
                    <input type="radio" name="sex" value="0" title="女">
                </div>
            </div>
            <label class="layui-form-label">地区:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="address" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入地区" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="phone" name="phone" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入电话" style="height: 30px;border-radius: 10px">
            </div>
            <label class="layui-form-label">职位:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="position" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入职位" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">日志类型:</label>
                <div class="layui-input-block">
                    <input type="radio" name="type" value="1"  title="超级管理员">
                    <input type="radio" name="type" value="0" checked title="系统日志">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">是否可用:</label>
                <div class="layui-input-block">
                    <input type="radio" name="available" value="1"  checked title="可用">
                    <input type="radio" name="available" value="0"  title="不可用">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;padding-right: 120px">
                <button type="button"
                        class="layui-btn layui-btn-normal layui-btn-md layui-icon layui-icon-release layui-btn-radius"
                        lay-filter="doSubmit" lay-submit="">提交
                </button>
                <button type="reset"
                        class="layui-btn layui-btn-warm layui-btn-md layui-icon layui-icon-refresh layui-btn-radius">重置
                </button>
            </div>
        </div>
    </form>
</div>
<%-- 添加或者修改弹出框结束 --%>

<script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script>
    var tab;
    layui.use(
        ['table', 'layer', 'form', 'jquery','laydate'], function () {
            var table = layui.table;
            var form = layui.form;
            var $ = layui.jquery;
            var layer = layui.layer;
            var laydate=layui.laydate;
            // var dtree = layui.dtree;

            laydate.render({
               elem:'#starttime',
               type:'datetime'
           })

            laydate.render({
                elem:'#endtime',
                type:'datetime'
            })

            tab = table.render({
                elem: '#logTable',
                url: "${pageContext.request.contextPath}/log/logShow",
                cellMinWidth: 30,
                page: {limit: 5, limits: [5, 10, 15, 20]},
                toolbar: '#toolbarlog',//开启头部工具栏，并为其绑定左侧模板
                cols: [[
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'id', width: 150, title: '日志ID', sort: true}
                    ,{field: 'loginname', width: 150, title: '登录名称', sort: true}
                    , {field: 'loginip', width: 200, title: '登录IP', sort: true}
                    , {field: 'logintime', width: 200, title: '登录时间'}
                    , {fixed: 'right', title: '操作', toolbar: '#barlog', width: 120}
                ]]
            })
            var index;
            //头工具栏事件
            table.on('toolbar(logTable)', function (obj) {
                if (obj.event == 'delBatch') {
                    delBatch()
                }
            })

            function delBatch(){
                var data1 = table.checkStatus('logTable').data
                // var data1=checkStatus.data;
                var ids="";
                var count=0;
                for(var i=0;i<data1.length;i++){
                    ids+=data1[i].id+",";
                    count++;
                }

                if(count == 0){
                    return;
                }
                ids = ids.substring(0,ids.length-1)

                layer.confirm("确定删除这"+count+"条数据吗",function(r){
                    layui.$.get("${pageContext.request.contextPath}/log/deleteAllLog?ids="+ids,function(rr){
                        layer.msg(rr.msg)
                        tab.reload()
                    })
                })
            }

            table.on('tool(logTable)', function (obj) {
                var data = obj.data
               if (obj.event == "del") { // 删除
                    logDelete(data.id)
                }
            })

            form.on('submit(doSearch)', function (data) {
                //ajax数据
                tab.reload({
                    where: data.field,
                    page:{curr:1}
                })
                //不跳转页面
                return false;
            })


            function logDelete(logid) {
                layer.confirm("确定要删除该数据吗？", function () {
                    $.post("${pageContext.request.contextPath}/log/logDelete", {"logid": logid}, function (r) {
                        layer.msg(r.msg)
                        tab.reload()
                    })
                })
            }

            var roleTable

            function sellogRole(data) {
                // 弹出框
                index = layer.open({
                    type: 1 // 1（页面层）
                    , title: "分配" + data.realname + "的角色"
                    , content: $("#sellogRoleDiv")
                    , area: ['600px', '380px']
                    , btn: ['<div class="layui-icon layui-icon-release">确认分配</div>'
                        , '<div class="layui-icon layui-icon-close">取消分配</div>']
                    , btnAlign: 'c'
                    , success: function () {
                        // 给roleTable赋值
                        roleTable = table.render({
                            elem: "#roleTable"
                            , url: "${pageContext.request.contextPath}/log/findRoleBylog?logid=" + data.logid
                            // ,page: {limit:5 ,limits:[5,10,15]} //开启分页
                            , cellMinWidth: 80
                            , cols: [[ //表头
                                {type: 'checkbox', fixed: 'left'}
                                , {field: 'roleid', title: '角色ID', fixed: 'center'}
                                , {field: 'rolename', title: '角色名称', fixed: 'center'}
                                , {field: 'roledesc', title: '角色描述', fixed: 'center'}
                            ]]
                        })
                    }
                    , yes: function (obj) {
                        var checkStatus = table.checkStatus("roleTable");
                        if (checkStatus.data.length == 0) {
                            layer.msg("至少选择一个")
                        } else {
                            // 获取日志id
                            var logid = data.logid
                            var param = "logid=" + logid

                            // 循环选中的内容nodes
                            $.each(checkStatus.data, function (i, item) {
                                param += "&ids=" + item.roleid
                            })
                            // A=valueA&B=valueB&B=valueB
                            // 把数据保存到数据库
                            $.get("${pageContext.request.contextPath}/log/saveRolelog?"+param, function (r) {
                                layer.msg(r.msg)
                            })
                        }
                        layer.close(index)
                    }
                })
            }


        })

</script>
</body>
</html>

